﻿using AutoMapper;
using MediatR;
using S.PurchaseAndSales.Domain.Model;
using S.PurchaseAndSales.Infrastructure.Interface.SalesForm;
using S.PurchaseAndSales.Read.Api.Application.Command.SheepSaleCommand;
using S.PurchaseAndSales.Read.Api.Dto;

namespace S.PurchaseAndSales.Read.Api.Application.CommandHandlers.SheepSaleHandler
{
    public class SaleFillSheepCommandHandler : IRequestHandler<SheepFillCommand, SheepFillGetByIdDto>
    {
        private readonly ISheepSaleRepository sheepSaleRepository;
        private readonly IMapper mapper;

        public SaleFillSheepCommandHandler(ISheepSaleRepository sheepSaleRepository,IMapper mapper)
        {
            this.sheepSaleRepository = sheepSaleRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 通过羊只销售主键获取羊只信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<SheepFillGetByIdDto> Handle(SheepFillCommand request, CancellationToken cancellationToken)
        {
            SheepSaleModel sheepSaleModel=await sheepSaleRepository.GetByIdAsync(request.SalId);
            SheepFillGetByIdDto sheepFillGetByIdDto = mapper.Map<SheepFillGetByIdDto>(sheepSaleModel);
            return sheepFillGetByIdDto;
        }
    }
}
